package com.common.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.common.R;
import com.common.event.InputCompleteEvent;
import com.common.event.LoginOutEvent;
import com.common.utility.CommonUtility;

import de.greenrobot.event.EventBus;

/**
 * 这个界面只有一个输入框，点击完成后，
 * 发送InputCompleteEvent event,其中包含value值
 * 这边后续要可扩展，比如定义EditText只能输入数字，长度....
 */
public class SelectInputActivity extends BaseActivity implements View.OnClickListener{

    private EditText mInputEditText;

    public final static String EXTRA_TITLE = "title";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_input);

        String title = getIntent().getStringExtra(EXTRA_TITLE);
        initActionBar();
        mActionBar.setNavTitle(title);
        mActionBar.setTextNavRight("完成");
        mActionBar.hideNavLeftText();

        mInputEditText = (EditText)findViewById(R.id.et_input);

    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        if(view.getId() == R.id.ll_nav_right) {
            save();
        }
    }

    public void save(){
        String value = mInputEditText.getText().toString();
        if(TextUtils.isEmpty(value)){
            CommonUtility.UIUtility.toast(activity,"内容不能为空!");
            return;
        }
        EventBus.getDefault().post(new InputCompleteEvent(value));
        SelectInputActivity.this.finish();
    }

    @Override
    public void onEvent(LoginOutEvent event) {
        finish();
    }
}
